import { baseApi } from './base';

interface IPostVo {
  id: number;
  name: string;
}
//使用base URL 和endpoints 定义服务
const userApi = baseApi.injectEndpoints({
  endpoints: (builder) => ({
    // 查询列表
    getUserList: builder.query<Promise<IPostVo[]>, void>({
      query: () => '/posts',
      transformResponse: (response: { data: Promise<IPostVo[]> }) => {
        console.log(response, '111');
        return response.data;
      },
    }),
  }),
  overrideExisting: true,
});
//导出可在函数式组件使用的hooks,它是基于定义的endpoints自动生成的
export const { useGetUserListQuery } = userApi;
export default userApi;
